package com.tianbo.elfii.client.common.wlanmanagement;

import java.awt.AlphaComposite;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.RenderingHints;
import java.awt.Robot;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.io.File;

import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

import com.tianbo.elfii.client.common.ElfiiCommonConstant;
import com.tianbo.elfii.client.common.ElfiiCommonRunInfo;
import com.tianbo.elfii.client.common.ElfiiCommonUtil;

public class BaseDialogPane extends JPanel {
	 BufferedImage infoImage;
     BufferedImage bgImg;
     BufferedImage bgImg2;

     protected int rectX0=242;
	protected int rectY0=220;
     int rectWidth=530,rectHeight=280;
 	
 	public String titleStr="";
 	public String mainStr="";
 	
 	public JFrame mainFrame;
 	
 	public JPanel backPanel;

     public BaseDialogPane(){

//  		 this.backPanel = backPanel;
  		 mainFrame = ElfiiCommonRunInfo.getRunInfo().getMainFrame();
         File f;
//         int x0=0,y0=0;
         try {
             f=new File("resource-common/images/config/icons/tb.png");
             infoImage=ImageIO.read(f);
             
             f=new File("resource-common/images/config/bg.png");
             bgImg2 = ImageIO.read(f);

             bgImg = null;
//             x0=(int) mainFrame.getLocationOnScreen().getX();
//             y0=(int) mainFrame.getLocationOnScreen().getY();
//             
//             Robot rbt = new Robot();
//             bgImg=rbt.createScreenCapture(new Rectangle(x0,y0,1024,768));
           
         } catch(Exception e) {System.out.print(e);}

		this.setLayout(null);

 		
     }
     
     public void screenshot(){
         try {
             int x0=(int) mainFrame.getLocationOnScreen().getX();
             int y0=(int) mainFrame.getLocationOnScreen().getY();
             Robot rbt = new Robot();
             bgImg=rbt.createScreenCapture(new Rectangle(x0,y0,1024,768));
             
         } catch(Exception e) {System.out.print(e);}
     }

     public void paintComponent(Graphics g) {
         super.paintComponent(g);
         Graphics2D g2 = (Graphics2D) g ;
         g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); 
         //g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.4f));   
         g2.drawImage(bgImg,null,0,0);
         //g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1.0f));   
         //g2.setStroke(new BasicStroke(1.0f));
         g2.drawImage(bgImg2, null, 0, 0);
//         g2.setColor(Color.white);
//         g2.fillRoundRect(rectX0,rectY0,rectWidth,rectHeight,10,10);
//         g2.setColor(Color.black);
//         g2.fillRoundRect(rectX0+5,rectY0+5,rectWidth-10,rectHeight-10,10,10);
//         g2.drawImage(infoImage,null,rectX0+30,rectY0+20);
//         g2.setColor(Color.gray);
//         g2.drawLine(rectX0+20,rectY0+85,rectX0+rectWidth-20,rectY0+85);
//         g2.fillRect(rectX0+5,rectY0+rectHeight-55,rectWidth-10,50);

     }
     
     public void setDialogBounds(int x,int y ,int width,int height){
    	 rectX0 = x;
    	 rectY0 = y;
    	 rectWidth = width;
    	 rectHeight = height;
     }
     
     public void showDialog(){
 		this.validate();
 		this.setVisible(true);
 	}
 	
 	public void initText(){
 		
 		JLabel titleLabel = new JLabel(titleStr);
 		titleLabel.setFont(new Font(ElfiiCommonConstant.Font_Name,Font.PLAIN,30));
 		titleLabel.setBounds(rectX0+105, rectY0+60, 50, 20);
 		titleLabel.setForeground(Color.white);
 		
 		JLabel mainLabel = new JLabel(mainStr);
 		mainLabel.setFont(new Font(ElfiiCommonConstant.Font_Name,Font.PLAIN,16));
 		mainLabel.setBounds(rectX0+110, rectY0+120, 100, 20);
 		mainLabel.setForeground(Color.white);

 		this.add(titleLabel);
 		this.add(mainLabel);
 	}
// 	
}
